<template>
	<view>
		<nav-bar title="地址选择"></nav-bar>
		<!-- <view class="row-between" @click="toMap">
			<view class="label">
				选择精准位置
			</view>
		</view> -->
		<view class="address" :style="{height:addressHeight}">
			<!-- <uni-indexed-list :options="cityList" :show-select="true" @click="bindClick" />
	   -->
			<t-index-address @select="select"></t-index-address>
		</view>
	</view>
</template>

<script>
	import {
		cityData
	} from '@/utils/city'
	export default {
		name: 'ChooseArea',
		data() {
			return {
				cityList: cityData, //引用json数据
				addressHeight: ''
			}
		},

		onLoad(options) {
			this.addressHeight = this.$store.getters.heightData.noTabMainHeight + 'px'
		},

		methods: {
			async select(e) {
				console.log(e);
				await this.myAmapFun.getRegeo({
					location: `${e.lng},${e.lat}`,
					success: succ => {
						console.log('高德地图返回--->', succ)
						const datas = {
							// city: succ[0].regeocodeData.addressComponent.adcode,
							cityString: succ[0].regeocodeData.addressComponent.province.includes('市') ?
								succ[0].regeocodeData.addressComponent.province : succ[0].regeocodeData
								.addressComponent.city,
							longitude: e.lng,
							latitude: e.lat
						}
						this.$store.commit('SET_CITYOBJECT', datas)
						this.$nextTick(() => {
							uni.navigateBack()
						})
					},
					fail: err => {
						console.log(err)
					}
				})
				console.log(e, '城市')
			},
			bindClick(e) {
				this.cityList.forEach((ele, i) => {
					ele.items.forEach((val, j) => {
						val.checked = false
					})
				});
				console.log('点击item，返回数据' + JSON.stringify(e))
			}
		}
	}
</script>
<style lang="scss" scoped>
	.row-between{
		width: 100vw;
		height: 80rpx;
		background: #dddddd;
		.label{
			width: 100%;
			text-align: center;
		}
	}
	.address {
		position: relative;
	}
</style>